import { _decorator, Component, Node, resources, Sprite, SpriteFrame, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('enemyContral')
export class enemyContral extends Component {
        speed:number = 100;
        //是否死亡
        isDie:boolean = false;
    start() {

    }

    update(deltaTime: number) {
   
       if(! this.isDie ){
        let newPosition = new Vec3(
            this.node.position.x,
            this.node.position.y - this.speed * deltaTime,
            this.node.position.z
           ) 
        this.node.setPosition(newPosition)
       }
      
         //超出屏幕销毁
         if(this.node.position.y<-852){
          
            this.node.destroy()
        }
    }

    //死亡方法
    die(){
        this.isDie = true;
        //先播放爆炸图片 然后在死
        resources.load("enemy0_die/spriteFrame",SpriteFrame,(err,texture)=>{
            this.node.getComponent(Sprite).spriteFrame = texture
            this.schedule(()=>{
              
                this.node.destroy()
            },0.3)
        })
       
    }
}


